package com.quanquan.management.repository;

import com.quanquan.management.entity.SysRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @author:lihonglinag
 * @date:2019-03-21 11:35
 * @version:v 1.0.0
 */
public interface SysRoleRepository extends JpaRepository<SysRole,String> {
    @Query(value = "select r.* from oo_sys_role r left join oo_sys_role_user ru on ru.role_id=r.id where ru.user_id = ?1",nativeQuery=true)
    List<SysRole> getRoleByUserId(String userId);

    List<SysRole> getByName(String name);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value="delete from oo_sys_role where id =?1" ,nativeQuery=true)
    public void removeShip(String roleId);


}
